package com.xjy.controller;

import com.github.pagehelper.PageInfo;
import com.xjy.pojo.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("/path")
public class pathController {
    @Autowired
    @Qualifier("pathServiceImpl")
    private com.xjy.service.pathService pathService;

    @RequestMapping("/allPath")
    public String allPath(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "5") int size, Model model){
        List<Path> paths = pathService.findAllPathsByPage(page,size);
        for (Path path : paths) {
            System.out.println(path);
        }
        //PageInfo就是一个分页Bean
        PageInfo pageInfo = new PageInfo(paths);
        model.addAttribute("PageInfo1",pageInfo);
        return "jsp/allPath";
    }



    @RequestMapping("/showPathInfo")
    public String showPathInfo(String pid,Model model){
        Path path = pathService.getPathInfoById(pid);
        model.addAttribute("pathInfo",path);
        List<Path> paths = pathService.getRandomPath();
        PageInfo pathList = new PageInfo(paths);
        model.addAttribute("pathList",pathList);
        return "jsp/pathInfo";
    }





}
